!pr2
Faster Amper-routine to Zero Arrays.........Johan Zwiekhorst
                                       Maasmechelen, Belgium

Although I have never subscribed to Apple Assembly Line, a friend of mine (who lives in nearby Heerlen, the Netherlands) does, and I always read his copies.

A few days ago I needed a routine to clear to zero all the elements in a number of Applesoft arrays, so I started looking in my friend's collection of AAL for such a program.  I found the article entitled "Save Garbage by Emptying Arrays" in the December 1982 issue, pages 22-25.

That routine, however, only cleared string arrays.  Bob designed it to set all strings in an array to null strings, so that garbage collection would be faster.  But I needed a fast way to clear integer and real arrays as well.  Bob's routine was also limited to clearing one array per call.

My routine clears any type of arrays, and can accept a list of array names separated by commas.  It uses the ampersand hook, like this:

       & CLEAR array1,array2,array3,...

You can load the routine in any available memory, anywhere you have a spare 79 bytes.  The listing shows it assembled into the ever-popular $300 space, but there are no internal addresses which require it to be there.  Just be sure you hook the ampersand to the program, wherever you put it.  If it is at $300, hook it like this:

       POKE 1013,76 : POKE 1014,0 : POKE 1015,3

The program is very similar to Bob's 1982 version:  I eliminated the check he made for string arrays, added ampersand control, and checked for a comma to allow a list of array names rather than just one.

Lines 1250-1260 check that the byte following the ampersand is the CLEAR token.  If not, a SYNTAX ERROR will result.  If it is CLEAR, all is well.

Lines 1280-1290 check for a comma, and are not used until we have finished clearing an array.  At the end, lines 1690-1710, you find my test after clearing an array.  If the next byte of program is not a colon or end of line, it will branch back to the comma-test.

The code in between zeroes all the data bytes in an array.  I could have done it the same way Bob did, but I did change a few things.  Compare mine with his and you will learn two ways to control a clearing loop.

How about a complete example of using &CLEAR?  Lets make three arrays, with a mixture of types and dimensions.  Of course, when the DIM statement works it initially zeroes the arrays, but I needed them cleared again later on.
       100 DIM A(10,20), B%(200,4,4), C%(20)
       110 PRINT CHR$(4)"BLOAD B.CLEAR ARRAYS,A$300"
       120 POKE 1013,76:POKE1014,0:POKE1015,3
       ...
       500 &CLEAR A,B%,C$
